// filename: IpEndpoint.h
// author: enic
// date: 2015-06-26

#pragma once

#include "import_stdlib.h"

class IpEndpoint
{
public:
	IpEndpoint()
	{
		SetIp(0);
		SetIp(0);
	}

	IpEndpoint(const std::string& strIp, uint16_t u16Port)
	{
		SetIp(IpFromString(strIp));
		SetIp(u16Port);
	}

	IpEndpoint(const std::wstring& strIp, uint16_t u16Port)
	{
		SetIp(IpFromString(strIp));
		SetIp(u16Port);
	}

	IpEndpoint(uint32_t u32Ip, uint16_t u16Port)
	{
		SetIp(u32Ip);
		SetPort(u16Port);
	}

	uint32_t GetIp() const
	{
		return m_u32IP;
	}

	const std::string GetIpAsString() const;

	void SetIp(uint32_t u32Ip)
	{
		m_u32IP = u32Ip;
	}

	uint16_t GetPort() const
	{
		return m_u16Point;
	}

	void SetPort(uint16_t u16Port)
	{
		m_u16Point = u16Port;
	}

private:
	uint32_t m_u32IP;
	uint16_t m_u16Point;

public:
	static uint32_t IpFromString(const std::string& strIp);
	static uint32_t IpFromString(const std::wstring& strIp);
	static IpEndpoint IpEndpointFromString(const std::string& strIpEndPoint);
	static IpEndpoint IpEndpointFromString(const std::wstring& strIpEndPoint);
	static IpEndpoint IpEndpointFromLoopBackPort(uint16_t u16Port);
};